<?php
declare(strict_types=1);
/**
 * Created by PhpStorm.
 * User: jiam
 * Date: 2018/6/24
 * Time: 15:05
 */

namespace ServerApp\lib\server\tcp;

use ServerApp\lib\server\model\swoole\DeviceList;
use Swoole\Http\Response;

/**
 * Class ServiceTool
 * @package ServerApp\lib\server\tcp
 */
trait ServiceTool
{
    /**
     * @param $device_id
     * @return int
     */
    public function deviceIdToFd($device_id)
    {
        $row = DeviceList::getInstance()->getRow($device_id);
        if (!$row) {
            return 0;
        }

        return $row[DeviceList::FD] ?? 0;
    }

//    public function run(Response $response, $cmd, $params) {
//        $arr = $this->push(...$params);
//
//        tracker(D, gettype($arr));
//
//        if(is_array($arr)) {
//            $response->end(json_encode($arr));
//        } elseif (is_string($arr)) {
//            tracker(I, $arr);
//            $response->end($arr);
//        } else {
//            $response->end('');
//        }
//
//        $GLOBALS['server']->reload();
//    }
}
